<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace extend\weixin\request;

use extend\weixin\BaseRequest;
use extend\weixin\WxConf;
use extend\weixin\WxPay;

/**
 * 关闭交易订单
 * ```php
 *  $request = new PayTradeClose('LS230254158789752211'， '关闭支付单');
 *
 *  $wxClient = \extend\Extend::wxpay()->setRequest($request);
 *  $state = $wxClient->execute();
 *  if ($state) {
 *       var_export($wxClient->result);
 *  } else {
 *       echo $wxClient->error;
 *  }
 *  ```
 * @auther clevstn
 * @since 1.0
 */
class PayTradeClose extends BaseRequest
{
    private $_out_trade_no;
    private $_serviceName;

    /**
     * @param string $serialNo 平台流水号
     * @param string $serviceName 服务名称
     * @link https://pay.weixin.qq.com/docs/merchant/apis/mini-program-payment/close-order.html
     */
    public function __construct($serialNo, $serviceName)
    {
        $this->_out_trade_no = $serialNo;
        $this->_serviceName = $serviceName;
    }

    public function responseCallback($response, WxPay $wxpay)
    {
        return null;
    }

    public function getServiceName()
    {
        return $this->_serviceName;
    }

    public function getMethodAsync()
    {
        return 'postAsync';
    }

    public function getChain()
    {
        $outTradeNo = $this->_out_trade_no;
        return "/v3/pay/transactions/out-trade-no/{$outTradeNo}/close";
    }

    public function getRequestOptions()
    {
        return [
            'json' => [
                'mchid' => WxConf::MERCHANT_ID,
            ],
            'verify' => false,
        ];
    }
}